package com.trg.designmodel.singleleton;

/**
 * @ClassName: SingleLetonTest07
 * @Description:       单例设计模式-懒汉式（静态内部类）
 * @Author: tangrg
 * @Date: 2021/6/30 17:01
 * @Version: 1.0
 * @Return:
 **/
public class SingleLetonTest07 {

    public static void main(String[] args) {
        SingleLeton07 instance = SingleLeton07.getInstance();
        SingleLeton07 instance2 = SingleLeton07.getInstance();
        System.out.println("单例设计模式-懒汉式（静态内部类）");
        System.out.println(instance == instance2);
        System.out.println("instance:" + instance.hashCode());
        System.out.println("instance2:" + instance2.hashCode());
    }
}

class SingleLeton07{
    private SingleLeton07(){}


    //提供一个静态的内部类，该类中有一个静态属性
    public static SingleLeton07 getInstance(){
        return SingletonInstance.INSTANCE;
    }
    //写一个静态内部类,该类中有一个静态属性 Singleton
    public  static class SingletonInstance{
        private static final SingleLeton07 INSTANCE = new SingleLeton07();

    }
}
